/*
 Oracle 21c Compatible Script
 Schema: CT
*/

-- 确保序列存在
DECLARE
  v_count NUMBER;
BEGIN
  SELECT COUNT(*) INTO v_count FROM all_sequences WHERE sequence_owner = 'CT' AND sequence_name = 'SEQ_T_BOOK_TYPE';
  IF v_count = 0 THEN
    EXECUTE IMMEDIATE 'CREATE SEQUENCE CT.seq_t_book_type START WITH 8 INCREMENT BY 1 NOCACHE NOCYCLE';
  END IF;
END;
/

-- ----------------------------
-- Table structure for T_BOOK_TYPE
-- ----------------------------
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE CT.T_BOOK_TYPE';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
/

CREATE TABLE CT.T_BOOK_TYPE (
  "BOOKTYPEID" NUMBER NOT NULL,
  "BOOKTYPENAME" VARCHAR2(254 BYTE) NOT NULL,
  "BOOKTYPEDESC" VARCHAR2(254 BYTE) NOT NULL
)
LOGGING
NOCOMPRESS
PCTFREE 10
INITRANS 1
STORAGE (
  INITIAL 65536 
  NEXT 1048576 
  MINEXTENTS 1
  MAXEXTENTS 2147483645
  BUFFER_POOL DEFAULT
)
;

-- ----------------------------
-- Records of T_BOOK_TYPE
-- ----------------------------
INSERT INTO CT.T_BOOK_TYPE VALUES ('1', '计算机科学', '计算机相关');
INSERT INTO CT.T_BOOK_TYPE VALUES ('2', '历史', '历史相关');
INSERT INTO CT.T_BOOK_TYPE VALUES ('3', '文学', '文学相关');
INSERT INTO CT.T_BOOK_TYPE VALUES ('4', '科幻', '科幻相关');
INSERT INTO CT.T_BOOK_TYPE VALUES ('6', '小说', '小说相关');
INSERT INTO CT.T_BOOK_TYPE VALUES ('7', '外语', '外语相关');

-- ----------------------------
-- Primary Key structure for table T_BOOK_TYPE
-- ----------------------------
ALTER TABLE CT.T_BOOK_TYPE ADD CONSTRAINT "SYS_C0011121" PRIMARY KEY ("BOOKTYPEID");

-- ----------------------------
-- Checks structure for table T_BOOK_TYPE
-- ----------------------------
ALTER TABLE CT.T_BOOK_TYPE ADD CONSTRAINT "SYS_C0011118" CHECK ("BOOKTYPEID" IS NOT NULL) ENABLE;
ALTER TABLE CT.T_BOOK_TYPE ADD CONSTRAINT "SYS_C0011119" CHECK ("BOOKTYPENAME" IS NOT NULL) ENABLE;
ALTER TABLE CT.T_BOOK_TYPE ADD CONSTRAINT "SYS_C0011120" CHECK ("BOOKTYPEDESC" IS NOT NULL) ENABLE;

-- ----------------------------
-- Triggers structure for table T_BOOK_TYPE
-- ----------------------------
CREATE OR REPLACE TRIGGER CT.t_book_type_trig 
BEFORE INSERT ON CT.T_BOOK_TYPE 
FOR EACH ROW
BEGIN
    SELECT seq_t_book_type.nextval INTO :new.booktypeid FROM dual;
END;
/




CREATE TABLE "SYSTEM"."T_BOOK_TYPE" (
                                        "BOOKTYPEID" NUMBER GENERATED BY DEFAULT AS IDENTITY (START WITH 8) PRIMARY KEY, -- 初始值从8开始
                                        "BOOKTYPENAME" VARCHAR2(254 CHAR) NOT NULL,
                                        "BOOKTYPEDESC" VARCHAR2(254 CHAR) NOT NULL
)
    NOCOMPRESS
PCTFREE 10
INITRANS 1
STORAGE (BUFFER_POOL DEFAULT)
DISABLE ROW MOVEMENT;

-- 插入数据（移除显式BOOKTYPEID）
INSERT INTO "SYSTEM"."T_BOOK_TYPE" ("BOOKTYPENAME", "BOOKTYPEDESC")
VALUES ('计算机科学', '计算机相关');
